Skip to content

feat(tui): add cancel agent confirmation dialog and related functiona…#27

Merged
cnjack merged 1 commit intomainfrom
feat/cancel-agent-confirm-dialog
Apr 19, 2026
Merged

feat(tui): add cancel agent confirmation dialog and related functiona…#27
cnjack merged 1 commit intomainfrom
feat/cancel-agent-confirm-dialog

Conversation

@cnjack
Copy link
Copy Markdown
Owner

@cnjack cnjack commented Apr 19, 2026

…lity

Summary by CodeRabbit

  • New Features

    • Added ability to cancel a running agent with Ctrl+C, featuring a confirmation dialog to prevent accidental cancellation.
    • Updated help footer to display the Ctrl+C cancellation option.
  • Improvements

    • Enhanced agent lifecycle management and interrupt handling.

@cnjack cnjack merged commit 5a93eb1 into main Apr 19, 2026
1 check was pending
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67890dca-703d-4b75-8cbd-b4646704004e

📥 Commits

Reviewing files that changed from the base of the PR and between 9395b54 and 27b198a.

📒 Files selected for processing (6)
  • Makefile
  • internal/command/interactive.go
  • internal/tui/messages.go
  • internal/tui/pickers.go
  • internal/tui/styles.go
  • internal/tui/tui.go

📝 Walkthrough

Walkthrough

This change refactors the TUI and interactive command handling to implement per-run agent context cancellation with a confirmation dialog, replacing channel-based auto-approve signaling with callback-based approval mode changes, and simplifying button styling by removing configurable spacing.

Changes

Cohort / File(s) Summary
Build Configuration
Makefile
Added a new fmt make target that runs goimports -w . with a status message, and updated .PHONY to include the target.
Context Cancellation & Error Handling
internal/command/interactive.go
Removed os import and replaced fatal error handling with error propagation. Introduced per-run context cancellation via cancelFunc and runCtx fields on interactiveState. Updated agent execution flow to create per-run contexts instead of using the global context. Replaced autoApproveCh event loop listening with independent background goroutine consuming cancelAgentCh for Ctrl+C handling. Updated TUI integration to use callback (WithApprovalModeChange) instead of channel-based approval signaling.
Message Channel Updates
internal/tui/messages.go
Removed autoApproveCh channel variable and GetAutoApproveChannel() accessor. Added cancelAgentCh (buffered struct channel) and GetCancelAgentChannel() accessor for delivering agent cancellation requests from TUI to main goroutine.
TUI Button Styling
internal/tui/styles.go
Simplified buttonGroup() function signature by removing the spacing parameter; function now uses fixed constant spacing (" ") between buttons.
TUI Dialog Components
internal/tui/pickers.go
Removed extra trailing argument (" ") from buttonGroup() calls in approval and exit dialogs. Added new cancelDialogView() method to render a centered warning-styled cancel confirmation dialog with computed dimensions, header, status line, button group, and input hint.
TUI Model & Integration
internal/tui/tui.go
Added cancel confirmation overlay with cancelPending/cancelSelected state and requestCancelAgent()/confirmCancelAgent() methods. Introduced OnApprovalModeChange callback field to Model and ModelOption type; replaced channel-based approval signaling with callback invocation. Updated RunTUI() signature to accept variadic ModelOption arguments. Modified tea.InterruptMsg (Ctrl+C) handling: while agent is running, open cancel confirmation instead of exit confirmation. Updated help footer and error messaging (detect "context canceled" and append muted cancellation indicator).

Sequence Diagram

sequenceDiagram
    actor User
    participant TUI as TUI Layer
    participant Handler as Command Handler
    participant Agent as Agent Runner
    
    rect rgba(200, 150, 100, 0.5)
    Note over User,Agent: Agent Cancellation Flow (New)
    User->>TUI: Press Ctrl+C
    TUI->>TUI: Open cancel confirmation dialog
    User->>TUI: Confirm cancellation
    TUI->>Handler: Send signal via cancelAgentCh
    Handler->>Handler: Call s.cancelFunc()
    Handler->>Agent: Context cancelled
    Agent->>Handler: Stop execution, return error
    Handler->>TUI: AgentDoneMsg with "context canceled"
    TUI->>User: Display "⏹ Agent cancelled."
    end
    
    rect rgba(100, 150, 200, 0.5)
    Note over User,Handler: Approval Mode Change Flow (New)
    User->>TUI: Press Ctrl+A or click "Approve all"
    TUI->>Handler: Invoke OnApprovalModeChange callback
    Handler->>Handler: Update approval state
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Fix/format #4: Modifies overlapping TUI files (internal/tui/tui.go, internal/tui/styles.go, internal/tui/pickers.go) with changes to model structure, function signatures, and view rendering logic.

Poem

🐰 A hopping refactor, oh what a sight!
Per-run contexts dancing, cancellations right!
Callbacks replace channels, a cleaner flow—
Ctrl+C confirms now, letting agents go.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cancel-agent-confirm-dialog

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cnjack cnjack deleted the feat/cancel-agent-confirm-dialog branch April 19, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant